<template>
	<el-dialog v-model="visible" :close-on-click-modal="false" :close-on-press-escape="false" :fullscreen="true">
		<el-tabs v-model="activeName" @tab-click="reloadDataList">
			<el-tab-pane label="入库明细" name="first">
				<Receiptdetail :dataForm1="dataForm" v-if="activeName == 'first' " ref="firstRef"></Receiptdetail>
			</el-tab-pane>
			<el-tab-pane label="入库明细记录" name="second" >
				<ReceiptdetaillistTab :dataForm="dataForm" v-if="activeName == 'second' " ref="secondRef" ></ReceiptdetaillistTab>
			</el-tab-pane>
		</el-tabs>
	</el-dialog>
</template>

<script>
	import Receiptdetail from "./Receiptdetail";
	import ReceiptdetaillistTab from "./ReceiptdetaillistTab";
	import {
		ref,
		reactive,
		onMounted,
		nextTick, watch
	} from 'vue';

	//import {getCodeListByCode} from "@/network/lswms/base/Codelist.js"
	//import {hasPermission} from "@/utils/hasPermission"
	export default {
		name: "orderdetail",

		components: {
			Receiptdetail,ReceiptdetaillistTab
		},

		setup() {
			const activeName = ref('first');

			const dataForm = ref({
				id: '',
				receiptkey: ''
			})

			const secondRefShow=()=>{

				secondRef.value.secondRef=true
			}
			const firstRef=ref(null)
			const visible = ref(false);
			const init = () => {

				visible.value = true;
				nextTick(function() {

					//  dataFormRef.value.resetFields();
					// roleIdListDefault.value = [];
					/*if (dataForm.value.receiptkey) {
						dataForm.value.id = '';

						  getDataList()
					}*/

				})
			}


			const secondRef = ref(null);
			const reloadDataList = (tab, event) => {
				// console.log(tab)
				// let tabName = tab.name;
				// if (tabName == 'first') {
				// 	firstRef.init();
				// }
				// if (tabName == 'second') {
				// 	secondRef.init();
				// }
			}

			watch(dataForm.value,()=>{
				activeName.value = 'second' ;
				 Promise.all(
					 activeName.value = 'second'
				 ).then(function() {
					 activeName.value = 'first' ;

				 }).catch((err) => {
				 	{
				 		console.log(err);
				 	}
				 })
			})

			return {
				activeName,
				dataForm,
				visible,
				init,
				reloadDataList,
				firstRef,
				secondRef,
				secondRefShow
			}
		},

	}
</script>

<style scoped>

</style>
